package com.njmd.mdbs.web.entity.sys;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import com.njmd.mdbs.web.entity.AuditableEntity;

/**
 * 用户实体
 * @author sunqw
 * @since 2013.10.12
 */
@Entity
@Table(name = "SYS_LOGIN")
public class SysLogin extends AuditableEntity implements Serializable
{
	private static final long serialVersionUID = 1L;
	/** 用户是否永久有效 1-有效 */
	public static final String USER_VALID_YES = "1";

	/** 用户是否永久有效 0-无效 */
	public static final String USER_VALID_NO = "0";

	/** 用户类型 0-超级管理员 */
	public static final int USER_TYPE_SUPER_ADMIN = 0;

	/** 用户类型 1-管理员 */
	public static final int USER_TYPE_ADMIN = 1;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "LOGIN_ID")
	private Long loginId;

	@Column(name = "LOGIN_LAST_TIME")
	private String loginLastTime;

	@Column(name = "LOGIN_NAME")
	private String loginName;

	@Column(name = "LOGIN_PWD")
	private String loginPwd;

	@Column(name = "RECORD_CORP_ID")
	private Long recordCorpId;

	@Column(name = "SEX")
	private String sex;

	@Column(name = "STATUS")
	private Integer status;

	@Column(name = "SYSTEM_ID")
	private Integer systemId;

	@Column(name = "TEL")
	private String tel;

	@Column(name = "USER_CODE",unique=true)
	private String userCode;

	@Column(name = "USER_NAME")
	private String userName;

	@Column(name = "USER_REMARK")
	private String userRemark;

	@Column(name = "USER_TYPE")
	private Integer userType;

	@Column(name = "VALID_DATE")
	private String validDate;

	@Column(name = "VALID_TAG")
	private String validTag;

	@Column(name="ID_CARD")
	private String idCard;
	
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "CORP_ID")
	private SysCorp sysCorp;

	//用户数据访问范围
	@Column(name="DATA_SCOPE")
	private String dataScope;
	
	@Column(name = "LOGIN_PWD_SALT")
	private String loginPwdSalt;

	public SysLogin()
	{
	}

	public Long getLoginId()
	{
		return loginId;
	}

	public void setLoginId(Long loginId)
	{
		this.loginId = loginId;
	}

	public String getLoginLastTime()
	{
		return loginLastTime;
	}

	public void setLoginLastTime(String loginLastTime)
	{
		this.loginLastTime = loginLastTime;
	}

	public String getLoginName()
	{
		return loginName;
	}

	public void setLoginName(String loginName)
	{
		this.loginName = loginName;
	}

	public String getLoginPwd()
	{
		return loginPwd;
	}

	public void setLoginPwd(String loginPwd)
	{
		this.loginPwd = loginPwd;
	}

	public Long getRecordCorpId()
	{
		return recordCorpId;
	}

	public void setRecordCorpId(Long recordCorpId)
	{
		this.recordCorpId = recordCorpId;
	}

	public String getSex()
	{
		return sex;
	}

	public void setSex(String sex)
	{
		this.sex = sex;
	}

	public Integer getStatus()
	{
		return status;
	}

	public void setStatus(Integer status)
	{
		this.status = status;
	}

	public Integer getSystemId()
	{
		return systemId;
	}

	public void setSystemId(Integer systemId)
	{
		this.systemId = systemId;
	}

	public String getTel()
	{
		return tel;
	}

	public void setTel(String tel)
	{
		this.tel = tel;
	}

	public String getUserCode()
	{
		return userCode;
	}

	public void setUserCode(String userCode)
	{
		this.userCode = userCode;
	}

	public String getUserName()
	{
		return userName;
	}

	public void setUserName(String userName)
	{
		this.userName = userName;
	}

	public String getUserRemark()
	{
		return userRemark;
	}

	public void setUserRemark(String userRemark)
	{
		this.userRemark = userRemark;
	}

	public Integer getUserType()
	{
		return userType;
	}

	public void setUserType(Integer userType)
	{
		this.userType = userType;
	}

	public String getValidDate()
	{
		return validDate;
	}

	public void setValidDate(String validDate)
	{
		this.validDate = validDate;
	}

	public String getValidTag()
	{
		return validTag;
	}

	public void setValidTag(String validTag)
	{
		this.validTag = validTag;
	}

	public String getIdCard()
	{
		return idCard;
	}

	public void setIdCard(String idCard)
	{
		this.idCard = idCard;
	}

	public SysCorp getSysCorp()
	{
		return sysCorp;
	}

	public void setSysCorp(SysCorp sysCorp)
	{
		this.sysCorp = sysCorp;
	}

	public String getDataScope()
	{
		return dataScope;
	}

	public void setDataScope(String dataScope)
	{
		this.dataScope = dataScope;
	}

	public String getLoginPwdSalt()
	{
		return loginPwdSalt;
	}

	public void setLoginPwdSalt(String loginPwdSalt)
	{
		this.loginPwdSalt = loginPwdSalt;
	}
	
	public String getCredentialsSalt()
	{
		return loginName + loginPwdSalt;
	}

	public boolean isSuperAdmin()
	{
		return this.userType.equals(SysLogin.USER_TYPE_SUPER_ADMIN);
	}

}